/**
 * Created by ${PRODUCT_NAME}.
 * User: skylerparr
 * Date: 1/9/11
 * Time: 3:10 PM
 * To change this template use File | Settings | File Templates.
 */
package com.thoughtorigin.meta {
import com.thoughtorigin.events.DataEvent;
import com.thoughtorigin.meta.MetaType;
import com.thoughtorigin.reflect.MetaDataItem;
import com.thoughtorigin.relay.MessageRelay;
import com.thoughtorigin.service.Message;

public class DataMetaData implements MetaType {

    private var _messageRelay: MessageRelay;

    public function DataMetaData() {
    }

    public function decorate(object:Object, metadata:MetaDataItem, callback:Function):void {
        var message: Message = new Message();
        message.serviceName = metadata.decoratedPropertyName + "Service";
        message.directCallback = function(me: DataEvent): void {
            object[metadata.decoratedPropertyName] = me.data;
            callback.call(this);
        };
        _messageRelay.relayMessage(message);
    }

    public function preprocess(clazz:Class, metadata:MetaDataItem):void {
    }

    public function get priority():int {
        return 0;
    }

    public function dispose(... args):void {
    }

    [Inject]
    public function set messageRelay(value: MessageRelay): void {
        _messageRelay = value;
    }
}
}
